﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Extensions.Logging;
using ZH.GPT.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace ZH.GPT.CustomFilter
{
    /// <summary>
    /// ActionFilter,空的，有需要了再加
    /// </summary>
    public class CustomActionFilterAttribute : ActionFilterAttribute
    {
        ILogger<CustomActionFilterAttribute> logger;
        MyContentResult myContentResult;
        /// <summary>
        /// 全局异常
        /// </summary>
        /// <param name="logger"></param>
        /// <param name="myContentResult"></param>
        public CustomActionFilterAttribute(ILogger<CustomActionFilterAttribute> logger, MyContentResult myContentResult)
        {
            this.logger = logger;
            this.myContentResult = myContentResult;
        }

        /// <summary>
        /// OnActionExecuted
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuted(ActionExecutedContext context)
        {
            //var result = context.Result as ObjectResult;
            //context.Result = myContentResult.Content(PackResult.Pack<object>(result.Value).ToString());
            //不建议在此操作返回值
            //1.Filter本身就存在少量性能消耗
            //2.此处处理要不封装返回对象时统一用一个，此种方式设计上会有缺陷，若用多个，会存在返回值不一致，就得用object，那么返回枚举的成功失败类型时就存在拆箱装箱，会有性能消耗
            //3.存在多种返回类型的转换和判断，也会带来性能的消耗

        }

        /// <summary>
        /// OnActionExecuting
        /// </summary>
        /// <param name="context"></param>
        public override void OnActionExecuting(ActionExecutingContext context)
        {
        }

        /// <summary>
        /// OnResultExecuting
        /// </summary>
        /// <param name="context"></param>
        public override void OnResultExecuting(ResultExecutingContext context)
        {
        }

        /// <summary>
        /// OnResultExecuted
        /// </summary>
        /// <param name="context"></param>
        public override void OnResultExecuted(ResultExecutedContext context)
        {
        }
    }
}
